package com.javaclimb.music.controller;

import com.alibaba.fastjson.JSONObject;
import com.javaclimb.music.domain.ListSong;
import com.javaclimb.music.service.ListSongService;
import com.javaclimb.music.utils.Consts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * 歌单里面歌曲controller
 * */
@RestController
@RequestMapping("/listSong")
public class ListSongController {

    @Autowired
    private ListSongService listSongService;

    /**
     * 给歌单添加歌曲
     * */
    @PostMapping("/add")
    public Object addListSong(ListSong listSong){
        //System.out.println(singer);
        //return singer;
        JSONObject jsonObject = new JSONObject();
        boolean flag = listSongService.insert(listSong);
        if(flag){
            jsonObject.put(Consts.CODE, 1);
            jsonObject.put(Consts.MSG, "保存成功");
            return jsonObject;
        }
        jsonObject.put(Consts.CODE, 0);
        jsonObject.put(Consts.MSG, "保存失败");
        return jsonObject;
    }

    /**
     * 根据歌单id查询歌曲
     *
     * */
    @GetMapping("/detail")
    public Object detail(Integer songListId){
        JSONObject jsonObject = new JSONObject();
        return listSongService.listSongOfSongListId(songListId);
    }

    /**
     * 修改歌单里的歌曲
     * */
    @PostMapping("/update")
    public Object updateListSong(ListSong listSong){
        JSONObject jsonObject = new JSONObject();
        boolean flag = listSongService.update(listSong);
        System.out.println();
        if(flag){
            jsonObject.put(Consts.CODE, 1);
            jsonObject.put(Consts.MSG, "修改成功");
            return jsonObject;
        }
        jsonObject.put(Consts.CODE, 0);
        jsonObject.put(Consts.MSG, "修改失败");
        return jsonObject;
    }

    /**
     * 删除歌单里的歌曲
     * */
    @GetMapping("/delete")
    public Object delete(Integer songId, Integer songListId){
        //return singer;
        boolean flag = listSongService.deleteBySongIdSongListId(songId, songListId);
        return flag;
    }

}
